/**
 * Created by Administrator on 2018/5/7.
 */
define(function (require,exports,module) {
    require("./sigin.css");
    var sTpl = require("./template.html");
    var rooms = require("../../sysSetting/rooms/room.js");
    var VueComponent = Vue.extend({
        props: ['parentData'],
        template: sTpl,
        components:{
            'rooms':rooms
        },
        methods: {
            handleSelect:function (val) {
                var $this = this;
                this.flightPlanes.forEach(function (data) {
                    if(data.value.planeId==val){
                        $this.currentFlightPlane=data.value;
                        axios.get(basepath+"/api/appointment/findAllAppointOfSignin?flightInfoId="+$this.currentFlightPlane.flightInfo.flightInfoId+
                            "&originating="+$this.currentFlightPlane.originating+"&destination="+$this.currentFlightPlane.destination+"&appoDate="+$this.currentFlightPlane.expectDate+
                            "&appProperty="+$this.currentFlightPlane.importOrExport+"&planeId="+$this.currentFlightPlane.planeId
                        ).then(function (response) {
                           $this.appointments=response.data;
                        });
                        return false;
                    }
                });


            },
            updateSigIn:function () {
                var $this = this;
                this.$refs.formInline.validate(function (validata) {
                    if(validata){
                        axios.post(basepath+"/api/signIn/save", {signInPo:$this.formInline, appointmentPo:$this.formInline.appointment?$this.formInline.appointment:{}}).then(function () {

                            $this.$notify({tittle:"更新成功",message:"更新成功"})
                        })
                    }
                });
            }
            ,

            saveSignIn:function () {
                var $this = this;
              this.$refs.formInline.validate(function (validata) {
                  if(validata){
                      axios.post(basepath+"/api/signIn/save", {signInPo:$this.formInline, appointmentPo:$this.formInline.appointment?$this.formInline.appointment:{}}).then(function () {
                          $this.$refs.formInline.resetFields();
                          $this.$notify({tittle:"保存成功",message:"签入保存成功"})
                      })
                  }
              });
            },
            selectRoom:function () {
                var $this= this;
                this.roomCon.selectRoom=this.formInline.room;
                this.roomCon.selectFunction=function (room) {
                    $this.formInline.room=room;
                }
            }
        },
        data:function () {
            return {
                formInline: {
                    "vipName":null,
                    "certificateType":null,
                    "certificateNum":null,
                    "phoneNum":null,
                    "sex":null,
                    "room":null,
                    "numberOfDelivery":0,
                    "numberOfPassengers":1,
                    "duties":null,
                    "specialDemand":null,
                    "accompanyingVehicle":null,
                     serviceStatus:'服务中',
                    "flightPlane":{planeId:''},
                     appointment:''
                },
                currentFlightPlane:{},
                flightPlanes:[],
                slidingWindowVisible1:false,
                appointments:[],
                roomCon:{

                }
        };
        },
        created:function (){

            var $this= this;
            axios.get(basepath+"/api/flightPlane/queryNow").then(function(response){
                var res=[];
                response.data.forEach(function (item,index) {
                    res[index]={};
                    var option=res[index];
                    if(item.importOrExport=='出港'){
                        option.label=item.flightInfo.flightNum+":"+item.originating+"-"+item.destination+":"+item.takeOffTime.substr(11,5)+"-"+item.arriveTime.substr(11,5);
                    }
                    if(item.importOrExport=='进港'){
                        option.label=item.flightInfo.flightNum+":"+item.originating+"-"+item.destination+":"+item.takeOffTime.substr(11,5)+"-"+item.arriveTime.substr(11,5)
                    }
                    if(item.importOrExport=='中转联程'){
                        option.label=item.flightInfo.flightNum+":"+item.originating+"-"+item.destination+":"+item.takeOffTime.substr(11,5)+"-"+item.arriveTime.substr(11,5)
                    }
                        option.value=item;
                        option.value.label=option.label;

                })
                $this.flightPlanes=res;
            })
        },
        activated:function () {
            messages.$emit('change','签入');
        }
    });
    return VueComponent;
});